package com.itheima.mapper;

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/*
  操作 员工表的 接口
    里面定义操作 表的方法
    由mybatis去实现该方法
    所以加 @Mapper注解
 */
@Mapper
public interface EmpMapper {
//    @Select("select count(*) from emp")
//    Long count();
//   @Select("select * from emp limit #{start},#{pageSize}")
//    List<Emp> list(Integer start, Integer pageSize);

   //不体现分页的基础sql
   List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);

   //批量删除写xml
    void delete(List<Integer> ids);

    @Insert("insert into emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "         values(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    @Select("select * from emp where id=#{id}")
    Emp findById(Integer id);
 //使用动态sql 完成更新  如果填写条件了就更新 没填写 不更新
    void update(Emp emp);

   @Select("select * from emp where username=#{username} and password=#{password}")
    Emp getUserByUsernameAndPassword(Emp emp);

    @Delete("delete from emp where dept_id = #{id}")
    void deleteByDeptId(Integer id);//id 部门id
}
